<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: MemCache::Server</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">MemCache::Server</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1_5_1/memcache_rb.html">
                vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This class represents a memcached server instance.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000118">alive?</a>&nbsp;&nbsp;
      <a href="#M000120">close</a>&nbsp;&nbsp;
      <a href="#M000117">inspect</a>&nbsp;&nbsp;
      <a href="#M000116">new</a>&nbsp;&nbsp;
      <a href="#M000119">socket</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CONNECT_TIMEOUT</td>
          <td>=</td>
          <td class="context-item-value">0.25</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
The amount of time to wait to establish a connection with a memcached
server. If a connection cannot be established within this time limit, the
server will be marked as down.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">RETRY_DELAY</td>
          <td>=</td>
          <td class="context-item-value">30.0</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
The amount of time to wait before attempting to re-establish a connection
with a server that is marked dead.

</td>
        </tr>
        </table>
      </div>
    </div>



    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">host</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The host the memcached server is running on.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">port</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The port the memcached server is listening on.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">retry</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The time of next retry if the connection is dead.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">status</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
A text status string describing the state of the server.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">weight</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The weight given to the server.

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000116" class="method-detail">
        <a name="M000116"></a>

        <div class="method-heading">
          <a href="#M000116" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(memcache, host, port = DEFAULT_PORT, weight = DEFAULT_WEIGHT)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a <a href="Server.html#M000116">new</a> <a
href="Server.html">MemCache::Server</a> object for the memcached instance
listening on the given host and port, weighted by the given weight.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000116-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000116-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb, line 749</span>
749:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">memcache</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span> = <span class="ruby-constant">DEFAULT_PORT</span>, <span class="ruby-identifier">weight</span> = <span class="ruby-constant">DEFAULT_WEIGHT</span>)
750:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;No host specified&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">host</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">host</span>.<span class="ruby-identifier">empty?</span>
751:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;No port specified&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">port</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_i</span>.<span class="ruby-identifier">zero?</span>
752: 
753:       <span class="ruby-ivar">@memcache</span> = <span class="ruby-identifier">memcache</span>
754:       <span class="ruby-ivar">@host</span>   = <span class="ruby-identifier">host</span>
755:       <span class="ruby-ivar">@port</span>   = <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_i</span>
756:       <span class="ruby-ivar">@weight</span> = <span class="ruby-identifier">weight</span>.<span class="ruby-identifier">to_i</span>
757: 
758:       <span class="ruby-ivar">@multithread</span> = <span class="ruby-ivar">@memcache</span>.<span class="ruby-identifier">multithread</span>
759:       <span class="ruby-ivar">@mutex</span> = <span class="ruby-constant">Mutex</span>.<span class="ruby-identifier">new</span>
760: 
761:       <span class="ruby-ivar">@sock</span>   = <span class="ruby-keyword kw">nil</span>
762:       <span class="ruby-ivar">@retry</span>  = <span class="ruby-keyword kw">nil</span>
763:       <span class="ruby-ivar">@status</span> = <span class="ruby-value str">'NOT CONNECTED'</span>
764:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000118" class="method-detail">
        <a name="M000118"></a>

        <div class="method-heading">
          <a href="#M000118" class="method-signature">
          <span class="method-name">alive?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Check whether the server connection is alive. This will cause the <a
href="Server.html#M000119">socket</a> to attempt to connect if it
isn&#8216;t already connected and or if the server was previously marked as
down and the retry time has been exceeded.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000118-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000118-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb, line 779</span>
779:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">alive?</span>
780:       <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">socket</span>
781:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000120" class="method-detail">
        <a name="M000120"></a>

        <div class="method-heading">
          <a href="#M000120" class="method-signature">
          <span class="method-name">close</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Close the connection to the memcached server targeted by this object. The
server is not considered dead.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000120-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000120-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb, line 819</span>
819:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
820:       <span class="ruby-ivar">@mutex</span>.<span class="ruby-identifier">lock</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@multithread</span>
821:       <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sock</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">closed?</span>
822:       <span class="ruby-ivar">@sock</span>   = <span class="ruby-keyword kw">nil</span>
823:       <span class="ruby-ivar">@retry</span>  = <span class="ruby-keyword kw">nil</span>
824:       <span class="ruby-ivar">@status</span> = <span class="ruby-value str">&quot;NOT CONNECTED&quot;</span>
825:     <span class="ruby-keyword kw">ensure</span>
826:       <span class="ruby-ivar">@mutex</span>.<span class="ruby-identifier">unlock</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@multithread</span>
827:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000117" class="method-detail">
        <a name="M000117"></a>

        <div class="method-heading">
          <a href="#M000117" class="method-signature">
          <span class="method-name">inspect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return a string representation of the server object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000117-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000117-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb, line 769</span>
769:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
770:       <span class="ruby-value str">&quot;&lt;MemCache::Server: %s:%d [%d] (%s)&gt;&quot;</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@port</span>, <span class="ruby-ivar">@weight</span>, <span class="ruby-ivar">@status</span>]
771:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000119" class="method-detail">
        <a name="M000119"></a>

        <div class="method-heading">
          <a href="#M000119" class="method-signature">
          <span class="method-name">socket</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Try to connect to the memcached server targeted by this object. Returns the
connected <a href="Server.html#M000119">socket</a> object on success or nil
on failure.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000119-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000119-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/memcache-client-1.5.1/memcache.rb, line 787</span>
787:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">socket</span>
788:       <span class="ruby-ivar">@mutex</span>.<span class="ruby-identifier">lock</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@multithread</span>
789:       <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@sock</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@sock</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">closed?</span>
790: 
791:       <span class="ruby-ivar">@sock</span> = <span class="ruby-keyword kw">nil</span>
792: 
793:       <span class="ruby-comment cmt"># If the host was dead, don't retry for a while.</span>
794:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@retry</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@retry</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
795: 
796:       <span class="ruby-comment cmt"># Attempt to connect if not already connected.</span>
797:       <span class="ruby-keyword kw">begin</span>
798:         <span class="ruby-ivar">@sock</span> = <span class="ruby-identifier">timeout</span> <span class="ruby-constant">CONNECT_TIMEOUT</span> <span class="ruby-keyword kw">do</span>
799:           <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@host</span>, <span class="ruby-ivar">@port</span>
800:         <span class="ruby-keyword kw">end</span>
801:         <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">'TCP_NODELAY'</span> <span class="ruby-keyword kw">then</span>
802:           <span class="ruby-ivar">@sock</span>.<span class="ruby-identifier">setsockopt</span> <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IPPROTO_TCP</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">TCP_NODELAY</span>, <span class="ruby-value">1</span>
803:         <span class="ruby-keyword kw">end</span>
804:         <span class="ruby-ivar">@retry</span>  = <span class="ruby-keyword kw">nil</span>
805:         <span class="ruby-ivar">@status</span> = <span class="ruby-value str">'CONNECTED'</span>
806:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-constant">SystemCallError</span>, <span class="ruby-constant">IOError</span>, <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">err</span>
807:         <span class="ruby-identifier">mark_dead</span> <span class="ruby-identifier">err</span>.<span class="ruby-identifier">message</span>
808:       <span class="ruby-keyword kw">end</span>
809: 
810:       <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@sock</span>
811:     <span class="ruby-keyword kw">ensure</span>
812:       <span class="ruby-ivar">@mutex</span>.<span class="ruby-identifier">unlock</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@multithread</span>
813:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>